<?php
/**
 * 配音接口
 */
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserMaterial;

//先从缓存里读取数据
$redis = SysResource::getRedis();
$redis_cache_key=REDIS_PREFIX."DUB_TYPE_";
$redis_cache_data=$redis->get($redis_cache_key);

if($redis_cache_data){

    //读取redis缓存
    $data=json_decode($redis_cache_data);
    Response::output(0,"查询成功1",$data,count($data));
}else{

    //查询数据库
    $db = SysResource::getDB(false);
    $UserMaterial = new UserMaterial($db);
    $da1=$UserMaterial->type_sub(4);
    if(!empty($da1)){
        foreach($da1 as $k=>&$v){
            $re=$UserMaterial->ones("video","video_id",["status"=>2,"video_type"=>3,"video_join_sub"=>$v['id']]);
            if(empty($re)){
                unset($da1[$k]);
            }
//        $v['children']=$re;
        }
        $da2=[];
        foreach($da1 as $kk=>$vv){
            $da2[]=$vv;
        }
        $redis->setex($redis_cache_key,15,json_encode($da2));
        Response::output(0,"查询成功",$da2,count($da2));
    }else{
        Response::output(0,"查询成功",[],0);
    }

}




